home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / cslib15b.zip / DEMO / ADDRESS / CSADDIO.H < prev    next >
C/C++ Source or Header  |  1994-12-20  |  7KB  |  182 lines

  1. #include "ctype.h" 
  2. #include "csa.h" 
  3. #include "csdb.h" 
  4.  
  5. #define NAME_LENGTH     40 
  6. #define ADRE_LENGTH     32 
  7. #define CITY_LENGTH     23 
  8. #define COUNT_LENGTH     32 
  9. #define ZIP_LENGTH     9 
  10. #define TEL_LENGTH     17 
  11. #define RELATION_LENGTH     10 
  12. #define INFO_LENGTH     70 
  13.  
  14. ////////// Indexes to be used with the 'order()' function./////////////
  15. #define UNSORTED     0
  16. #define NAME_INDEX     1 
  17. #define CITY_INDEX     2 
  18. #define BIRTH_INDEX     3 
  19. #define RELATION_INDEX     4 
  20.  
  21. typedef struct 
  22. {
  23.    char   _name[NAME_LENGTH+1]; 
  24.    char   _adre[ADRE_LENGTH+1]; 
  25.    char   _city[CITY_LENGTH+1]; 
  26.    char   _count[COUNT_LENGTH+1]; 
  27.    char   _zip[ZIP_LENGTH+1]; 
  28.    char   _tel[TEL_LENGTH+1]; 
  29.    long   __update; 
  30.    long   __birth; 
  31.    char   _relation[RELATION_LENGTH+1]; 
  32.    char   _info[INFO_LENGTH+1]; 
  33. } record;
  34.  
  35. class NAM_foundation
  36. {
  37.  protected:
  38.  
  39.    record rec;
  40.    record *recp;
  41.  
  42.    long current;
  43.    int  dirty;
  44.    int  is_open;
  45.  
  46.  
  47.    void (NAM_foundation::*skip_fun)(int delta);
  48.    void (NAM_foundation::*top_fun)(void);
  49.    void (NAM_foundation::*bottom_fun)(void);
  50.    int  (NAM_foundation::*search_fun)(void *k);
  51.  
  52.    TBASE  db;
  53.    BTREEa in1;        //Index on field name  
  54.    BTREEa in2;        //Index on field city  
  55.    BTREEl in3;        //Index on field birth  
  56.    BTREEa in4;        //Index on field relation  
  57.  
  58.    DATE  _update;
  59.    DATE  _birth;
  60.  
  61.    void top0(void)    { current=1; }
  62.    void top1(void)    { in1.min_dat(¤t); }
  63.    void top2(void)    { in2.min_dat(¤t); }
  64.    void top3(void)    { in3.min_dat(¤t); }
  65.    void top4(void)    { in4.min_dat(¤t); }
  66.  
  67.    void bottom0(void)    { current=db.numrec(); }
  68.    void bottom1(void)    { in1.max_dat(¤t); }
  69.    void bottom2(void)    { in2.max_dat(¤t); }
  70.    void bottom3(void)    { in3.max_dat(¤t); }
  71.    void bottom4(void)    { in4.max_dat(¤t); }
  72.  
  73.    int  search0(void * )    { return TRUE; } 
  74.    int  search1(void *k)    { return in1.search_dat_ge(k,¤t); }
  75.    int  search2(void *k)    { return in2.search_dat_ge(k,¤t); }
  76.    int  search3(void *k)    { return in3.search_dat_ge(k,¤t); }
  77.    int  search4(void *k)    { return in4.search_dat_ge(k,¤t); }
  78.  
  79.    void skip0(int delta)    { current=max(min(current+delta,db.numrec()),1); }
  80.    void skip1(int delta)    { in1.skip_dat(delta,¤t); }
  81.    void skip2(int delta)    { in2.skip_dat(delta,¤t); }
  82.    void skip3(int delta)    { in3.skip_dat(delta,¤t); }
  83.    void skip4(int delta)    { in4.skip_dat(delta,¤t); }
  84.  
  85.    void in1_ins_tok(void *s)    { in1.insert(s,¤t); }
  86.    void in1_del_tok(void *s)    { in1.delet(s,¤t); }
  87.  
  88.    void tokenize(char *s,void(NAM_foundation::*fun)(void *));
  89.  
  90.  public:
  91.  
  92.  //////////////////////////////// class constructor ////////////////////////////
  93.    NAM_foundation(void); 
  94.  
  95.  //////////////////////////////// class destructor /////////////////////////////
  96.    ~NAM_foundation(void)  { close(); }
  97.  
  98.  //////////////////////////////// current record number ////////////////////////
  99.    long curr_rec(void)   { return current; }
  100.  
  101.  //////////////////////////////// define ///////////////////////////////////////
  102.    void define(void);  
  103.  
  104.  //////////////////////////////// open & close ////////////////////////////////
  105.    void open(void);  
  106.    void close(void);  
  107.  
  108.  //////////////////////////////// delete //////////////////////////////////////
  109.    int  is_delet(void)  { return db.is_delet(current); } 
  110.    void undelet(void)   { db.undelet(current); }         
  111.    void delet(void)     { db.delet(current); }           
  112.  
  113.  //////////////////////////////// number of records ///////////////////////////
  114.    long numrec(void)         { return db.numrec(); } 
  115.  
  116.  //////////////////////////////// import/export ///////////////////////////////
  117.    int  import(char *s);
  118.    int  export(char *s);
  119.    int  to_DBASE(char *s);
  120.  
  121.  //////////////////////////////// read/write current record ///////////////////
  122.  
  123.    void write_rec2(void);
  124.    void write_rec(void) { if(dirty) write_rec2(); }
  125.  
  126.    void read_rec(void) 
  127.    {
  128.         recp=(record *)db.locate_rec(current); 
  129.         rec=*recp; 
  130.         _update.sem_jul(rec.__update); 
  131.         _birth.sem_jul(rec.__birth); 
  132.    }
  133.  
  134.  //////////////////////////////// reindexing //////////////////////////////////
  135.    void reindex(void); 
  136.  
  137.  //////////////////////////////// append //////////////////////////////////////
  138.    void append(void);        //Indexes are NOT updated.
  139.    void append_blank(void);  //Indexes ARE updated.
  140.  
  141.  //////////////////////////////// pack ////////////////////////////////////////
  142.    void pack(void);
  143.  
  144.  //////////////////////////////// set active index ////////////////////////////
  145.    void order(int nr);    
  146.  
  147.  //////////////////////////////// relocating //////////////////////////////////
  148.    int  skip(int del); 
  149.    void bottom(void)     { write_rec(); (this->*bottom_fun)(); read_rec(); }  
  150.    void top(void)        { write_rec(); (this->*top_fun)(); read_rec(); }  
  151.    void search(void *k)  { write_rec(); if(!(this->*search_fun)(k)) bottom(); read_rec(); }
  152.    void go_to(long n)    { write_rec(); current=max(min(n,db.numrec()),1); read_rec(); }
  153.  
  154.  /////////////////////////reading fields //////////////////////////////////////
  155.     char * name(void)           { return rec._name; } 
  156.     char * adre(void)           { return rec._adre; } 
  157.     char * city(void)           { return rec._city; } 
  158.     char * count(void)          { return rec._count; } 
  159.     char * zip(void)            { return rec._zip; } 
  160.     char * tel(void)            { return rec._tel; } 
  161.     char * update(void)         { return (char *)_update; } 
  162.     char * birth(void)          { return (char *)_birth; } 
  163.     char * relation(void)       { return rec._relation; } 
  164.     char * info(void)           { return rec._info; } 
  165.  
  166.  /////////////////////////writing fields //////////////////////////////////////
  167.  // Note: when writing strings there are NO checks on the 
  168.  //       length. A string which is longer then the definition 
  169.  //       of the field indicates, will OVERWRITE other data!!     
  170.  //   
  171.     void   name(char *s)        { strcpy(rec._name,s); dirty=TRUE; } 
  172.     void   adre(char *s)        { strcpy(rec._adre,s); dirty=TRUE; } 
  173.     void   city(char *s)        { strcpy(rec._city,s); dirty=TRUE; } 
  174.     void   count(char *s)       { strcpy(rec._count,s); dirty=TRUE; } 
  175.     void   zip(char *s)         { strcpy(rec._zip,s); dirty=TRUE; } 
  176.     void   tel(char *s)         { strcpy(rec._tel,s); dirty=TRUE; } 
  177.     void   update(char *s)      { _update=s; dirty=TRUE; } 
  178.     void   birth(char *s)       { _birth=s; dirty=TRUE; } 
  179.     void   relation(char *s)    { strcpy(rec._relation,s); dirty=TRUE; } 
  180.     void   info(char *s)        { strcpy(rec._info,s); dirty=TRUE; } 
  181.  
  182. };